#include "llcomp_llc.h" 

    

        typedef  double vnd_t [3];
        typedef  double real8;
     
     void loopParallelFor0_support(  vnd_t *f,  int *_np,  vnd_t *pos,  vnd_t *vel,  vnd_t *a,  int *_nd,  int *_i,  real8 *_dt,  real8 *_rmass,  int *_j) ;
     void loopParallelFor0_support(  vnd_t *f,  int *_np,  vnd_t *pos,  vnd_t *vel,  vnd_t *a,  int *_nd,  int *_i,  real8 *_dt,  real8 *_rmass,  int *_j)  {
                 int np = *_np;
                 int nd = *_nd;
                 int i = *_i;
                 real8 dt = *_dt;
                 real8 rmass = *_rmass;
                 int j = *_j;
        /* Begin template: forall_init_unit.tmpl */

/* $0 => Variable del bucle
 * loop_initial => Valor inicial de la variable del bucle B
 * loop_finalice => Valor final de la variable del bucle C
 */

{
    int llc_meanT, llc_rnT;
    register int llc_i;

    llc_nT = ((np - 1) - (0) + 1);
    /* Medium number of tasks */
    llc_meanT = llc_nT / LLC_NUMPROCESSORS;
    /* Number of unassigned tasks */
    llc_rnT = llc_nT % LLC_NUMPROCESSORS;

    LLC_CHECK_MALLOC (llc_F, (LLC_NUMPROCESSORS + 1), int);

    llc_F[0] = 0;
    for (llc_i = 1; llc_i < (LLC_NUMPROCESSORS + 1); llc_i++) {
        llc_F[llc_i] = llc_F[llc_i-1] + llc_meanT + (((llc_i - 1) < llc_rnT) ? 1 : 0);
    }
}

/* End template: forall_init_unit.tmpl */
/* Begin template: forall_exec_unit.tmpl */

/* loop_var => Variable del bucle
 * loop_initial => Valor inicial de la variable del bucle
 * loop_stmt => Bloque del bucle
 */

{
    int llc_nP;
    int llc_grp_save;
    register int llc_i;

    llc_nP = LLC_NUMPROCESSORS;
    llc_grp_save = LLC_NAME;
    LLC_NUMPROCESSORS = 1;
    LLC_NAME = 0;
    
    i = (0) + llc_F[llc_grp_save];
    for (llc_i = 0; llc_i < LLC_PROCSGRP(llc_grp_save); llc_i++, i++) {
        
{

  for (j= 0; j < nd; (j++ ))  
{

pos[i][j]= (pos[i][j] + (vel[i][j] * dt)) + (((0.5 * dt) * dt) * a[i][j]);
vel[i][j]= vel[i][j] + ((0.5 * dt) * ((f[i][j] * rmass) + a[i][j]));
a[i][j]= f[i][j] * rmass;
  }

 ;
}

;
    }

    LLC_NAME = llc_grp_save;
    LLC_NUMPROCESSORS = llc_nP;
}

/* End template: forall_exec_unit.tmpl */
/* Begin template: forall_comm_res_unit.tmpl */

/* loop_var => Variable del bucle
 * loop_initial => Valor inicial de la variable del bucle
 * loop_finalice => Valor final de la variable del bucle
 * forall_comm_res_init => template dinamico que se utiliza para reservar memoria para las comunicaciones
 * forall_comm_res_pack => template dinamico que se utiliza para realizar las comunicaciones
 */

{
    register int llc_i, llc_j;
    long llc_buf_size = 0, llc_size_tmp = 0;
    char *llc_buf = NULL, *llc_buf_ptr = NULL;

    for (llc_i = 0; llc_i < LLC_NUMPROCESSORS; llc_i++) {
        llc_size_tmp = 0;
        for (llc_j = 0, i = (0) + llc_F[llc_i]; llc_j < LLC_PROCSGRP(llc_i); llc_j++, i++) {
            llc_size_tmp += (1) * sizeof ((&pos[i])[0]);
llc_size_tmp += (1) * sizeof ((&vel[i])[0]);
llc_size_tmp += (1) * sizeof ((&a[i])[0]);

        }
        llc_buf_size = LLC_MAX(llc_buf_size, llc_size_tmp);
    }

    if (llc_buf_size > 0) {
        LLC_CHECK_MALLOC (llc_buf, llc_buf_size, char);
        for (llc_i = 0; llc_i < LLC_NUMPROCESSORS; llc_i++) {
            if (llc_i == LLC_NAME) {
                llc_buf_ptr = llc_buf;
                for (llc_j = 0, i = (0) + llc_F[llc_i]; llc_j < LLC_PROCSGRP(llc_i); llc_j++, i++) {
                    /* Packing &pos[i]... */
memcpy (llc_buf_ptr, &pos[i], (1) * sizeof ((&pos[i])[0]));
llc_buf_ptr += (1) * sizeof ((&pos[i])[0]);
/* Packing &vel[i]... */
memcpy (llc_buf_ptr, &vel[i], (1) * sizeof ((&vel[i])[0]));
llc_buf_ptr += (1) * sizeof ((&vel[i])[0]);
/* Packing &a[i]... */
memcpy (llc_buf_ptr, &a[i], (1) * sizeof ((&a[i])[0]));
llc_buf_ptr += (1) * sizeof ((&a[i])[0]);

                }
                MPI_Bcast(llc_buf, (llc_buf_ptr - llc_buf), MPI_BYTE, llc_i, *llc_CurrentGroup);
            }
            else {
                llc_size_tmp = 0;
                for (llc_j = 0, i = (0) + llc_F[llc_i]; llc_j < LLC_PROCSGRP(llc_i); llc_j++, i++) {
                    llc_size_tmp += (1) * sizeof ((&pos[i])[0]);
llc_size_tmp += (1) * sizeof ((&vel[i])[0]);
llc_size_tmp += (1) * sizeof ((&a[i])[0]);

                }
                MPI_Bcast(llc_buf, llc_size_tmp, MPI_BYTE, llc_i, *llc_CurrentGroup);
                llc_buf_ptr = llc_buf;
                for (llc_j = 0, i = (0) + llc_F[llc_i]; llc_j < LLC_PROCSGRP(llc_i); llc_j++, i++) {
                        /* Unpacking &pos[i]... */
memcpy (&pos[i], llc_buf_ptr, (1) * sizeof ((&pos[i])[0]));
llc_buf_ptr += (1) * sizeof ((&pos[i])[0]);

    /* Unpacking &vel[i]... */
memcpy (&vel[i], llc_buf_ptr, (1) * sizeof ((&vel[i])[0]));
llc_buf_ptr += (1) * sizeof ((&vel[i])[0]);

    /* Unpacking &a[i]... */
memcpy (&a[i], llc_buf_ptr, (1) * sizeof ((&a[i])[0]));
llc_buf_ptr += (1) * sizeof ((&a[i])[0]);


                }
            }
        }
        free (llc_buf);
    }
}

/* End template: forall_comm_res_unit.tmpl */
/* Begin template: forall_exit.tmpl */

    free(llc_F);
    llc_F = NULL;

/* End template: forall_exit.tmpl */

                *_np = np;
                *_nd = nd;
                *_i = i;
                *_dt = dt;
                *_rmass = rmass;
                *_j = j;

    }

    